/**
 * 
 */
package info.niwota.js;

import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @author qiangli
 * 
 */
public class BaseCompressor {
	public static int BUFSIZE = 1024;

	public void compress(byte[] script, OutputStream out) throws Exception {
	}

	protected void close(Closeable os) {
		try {
			os.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	
	protected void copy(byte[] ba, OutputStream os) throws IOException {
		InputStream is = new ByteArrayInputStream(ba);
		copy(is, os);
		is.close();
	}
	
	protected void copy(InputStream is, OutputStream os) throws IOException {
		byte[] buf = new byte[BUFSIZE];
		while (true) {
			int read = is.read(buf);
			if (read == -1) {
				break;
			}
			if (read > 0) {
				os.write(buf, 0, read);
			}
		}
		os.flush();
	}
}
